package balmysundaycandy.marble.controller.snatch;

import java.util.List;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;

import balmysundaycandy.marble.broker.meta.TestMeta;
import balmysundaycandy.marble.broker.model.Test;

import com.google.appengine.api.datastore.Entity;

public class Slim3DatastoreQueryAndGetAndDeleteController extends Controller {

	@Override
	protected Navigation run() {
		// query
		List<Test> tests = Datastore.query(new TestMeta()).asList();
		
		for (int i = 0; i < tests.size(); i++) {
			if (i % 3 == 0) {
				// get and delete
				Entity hoge = Datastore.get(tests.get(i).getKey());
				Datastore.delete(hoge.getKey());
			}
		}

		return forward("/WEB-INF/jsp/snatch.jsp");
	}
}
